package com.asa.chart;

import java.util.ArrayList;
import java.util.List;

import com.asa.HanShu;

public class MathPointUtil {

	
	/**
	 * 画函数的曲线，我先试试看能不能用很多很多的点来表达
	 */
	public static double[][] hanshupoint(HanShu hanShu){
		double maxx = 10000;
		double buchang = 0.01;
		double[][] xy = new double[10000][];
		
		
		for (int i = 0; i < maxx; i++) {
			
			double y = hanShu.hanshu((i-maxx/2) * buchang);
			
			double[] ss = new double[2];
			
			ss[0] = (i-maxx/2)*buchang;
			ss[1] = y; 

			xy[i] = ss;

		}
		
		return xy;
	}
	
	
	/**
	 * 确定函数范围函数的线
	 * @param hanShu
	 * @param fanweifrom
	 * @param fanweito
	 * @return
	 */
	public static double[][] hanshupoint(HanShu hanShu,double fanweifrom,double fanweito){
		double buchang = 0.001;
		List<double[]> asa = new ArrayList<double[]>(); 

		double now = fanweifrom;
		
		while (true) {
			
			double y = hanShu.hanshu(now);
			double[] ss = new double[2];
			
			ss[0] = now;
			ss[1] = y; 

			asa.add(ss);
			
			
			now += buchang;
			if (now > fanweito) {
				break;
			}
			
		}
		double[][] xy = new double[asa.size()][];

		for (int i = 0; i < xy.length; i++) {
			xy[i] = asa.get(i);
		}	
		return xy;
	}
	
	/**
	 * 将两个数组缝合成一个可以用来画线的二维数组
	 * @param x
	 * @param y
	 * @return
	 */
	public static double[][] x_y2xy(double x[],double y[]){
		if (x.length!=y.length) {
			throw new RuntimeException("x数组和y数组长度不相等，缝合报错");
		}
		
		double[][] xy = new double[x.length][];
		for (int i = 0; i < x.length; i++) {
			xy[i] = new double[2];
			
			xy[i][0] = x[i];
			xy[i][1] = y[i];
		}	
		
		return xy;
	}
	
	
	
	
	
	
	/**
	 * 在平面上画一个点
	 * @param x
	 * @param y
	 * @return
	 */
	public static List<double[][]> drawpoint_x(double x,double y){
		List<double[][]> zhi = new ArrayList<double[][]>();
		double[][] hanshupoint = new double[2][];
		hanshupoint[0] = new double[]{x-0.03,y-0.03};
		hanshupoint[1] = new double[]{x+0.03,y+0.03};
		double[][] hanshupoint2 = new double[2][];
		hanshupoint2[0] = new double[]{x+0.03,y-0.03};
		hanshupoint2[1] = new double[]{x-0.03,y+0.03};
		zhi.add(hanshupoint);
		zhi.add(hanshupoint2);
		
		
		return zhi;
	}

	
	
	
	
}
